/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.util;

import java.util.ResourceBundle;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

/**
 *
 * @author jasuke
 */
public class Messager {
    private static final FacesContext context = FacesContext.getCurrentInstance();
    private static FacesMessage msg = null;
    private static ResourceBundle 
            bundle = ResourceBundle.getBundle("resources.Bundle", context.getViewRoot().getLocale());
    
    public Messager() {
                
    }

    public static void showInfo(String info) {
        if (!info.equals("")) {
            msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Info", info);
            FacesContext.getCurrentInstance().addMessage(null, msg);  
        }
    }
    
    public static void showWarning(String propertiesValue) {
        if (!propertiesValue.equals("")) {
            String message = bundle.getString(propertiesValue);
            msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Warning", message);
            FacesContext.getCurrentInstance().addMessage(null, msg);  
        }
    }
    
    public static void showError(String propertiesValue) {
        if (!propertiesValue.equals("")) {
            String message = bundle.getString(propertiesValue);
            msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", message);
            FacesContext.getCurrentInstance().addMessage(null, msg);  
        }
    }
    
    public static void showSaveUpdateStatus(boolean status) {
        String message;
        if (status) message = bundle.getString("succesSaving");
        else message = bundle.getString("failSaving");
        
        if (status) msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Info", message);
        else msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", message);
        
        FacesContext.getCurrentInstance().addMessage(null, msg);  
    }
    
    public static void showDeleteStatus(boolean status) {
        String message;
        if (status)
            message = bundle.getString("succesDelete");
        else 
            message = bundle.getString("failDelete");
        
        if (status) msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Info", message);
        else msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", message);
        
        FacesContext.getCurrentInstance().addMessage(null, msg);  
    }
    
    public static void showDeleteStatusConstaint(boolean status) {
        String message;
        if (status)
            message = bundle.getString("succesDelete");
        else 
            message = bundle.getString("failDeleteConstaint");
        
        if (status) msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Info", message);
        else msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", message);
        
        FacesContext.getCurrentInstance().addMessage(null, msg);  
    }
    
}
